﻿using Aspose.Words;
using Aspose.Words.Drawing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace LeHouse.Server.WebApi.Common
{
    public class ReplaceAndInsertImage : IReplacingCallback
    {
        /// <summary>
        /// 需要插入的图片路径
        /// </summary>
        public string url { get; set; }

        public ReplaceAndInsertImage(string url)
        {
            this.url = url;
        }

        public ReplaceAction Replacing(ReplacingArgs e)
        {
            //获取当前节点
            var node = e.MatchNode;
            //获取当前文档
            Document doc = node.Document as Document;
            DocumentBuilder builder = new DocumentBuilder(doc);
            //将光标移动到指定节点
            builder.MoveTo(node);
            //插入图片
            builder.InsertImage(url, 140, 140);
            return ReplaceAction.Replace;
        }
    }


    public class ReplaceAndInsertImage2 : IReplacingCallback
    {
        /// <summary>
        /// 需要插入的图片路径
        /// </summary>
        public string url { get; set; }

        public ReplaceAndInsertImage2(string url)
        {
            this.url = url;
        }

        public ReplaceAction Replacing(ReplacingArgs e)
        {
            //获取当前节点
            var node = e.MatchNode;
            //获取当前文档
            Document doc = node.Document as Document;
            DocumentBuilder builder = new DocumentBuilder(doc);
            //将光标移动到指定节点
            builder.MoveTo(node);
            //插入图片
            builder.InsertImage(url,400, 700);
            return ReplaceAction.Replace;
        }
    }






    //public class ReplaceAndInsertImage2 : IReplacingCallback
    //{
    //    /// <summary>
    //    /// 需要插入的图片路径
    //    /// </summary>
    //    public string url { get; set; }

    //    public ReplaceAndInsertImage2(string url)
    //    {
    //        this.url = url;
    //    }

    //    public ReplaceAction Replacing(ReplacingArgs e)
    //    {
    //        //获取当前节点
    //        var node = e.MatchNode;
    //        //获取当前文档
    //        Document doc = node.Document as Document;
    //        DocumentBuilder builder = new DocumentBuilder(doc);
    //        //将光标移动到指定节点
    //        builder.MoveTo(node);
    //        //插入图片
    //        builder.InsertImage(url, RelativeHorizontalPosition.Default, 0, RelativeHorizontalPosition.Default, 0, 150, 125,);
    //        return ReplaceAction.Replace;
    //    }
    //}

}